<template>
	<view>
		<view class="uni-column" style="margin-top: 25px;width: 90%;margin-left: 5%;">
			<input class="uni-input input" v-model="newpassword" type="number" placeholder="请输入新密码" />
			<input class="uni-input input" v-model="password"   placeholder="请输入重复密码" />
		</view>
		<view class="uni-column" style="padding-top: 20px; padding-bottom: 60px;width: 90%;margin-left: 5%;">
			<button class="loginbtn" @click="changepassword()">修改密码</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				newpassword:'',
				password:'',
				httpurl: getApp().globalData.weburl,
			}
		},
		methods: {
			changepassword(){
				var that = this;
				if(that.newpassword == that.password){
					uni.request({
						url: that.httpurl+'updateManagerInfo', //服务器地址+接口名
						data: {
						  userid:getApp().globalData.userid,
						  newpassword:this.password,
						},
						method: 'POST',
						header: {
						  'X-Requested-With': 'XMLHttpRequest',
						  "Accept": "application/json",
						  "Content-Type": "application/json; charset=UTF-8"
						 },
						dataType: 'json',
					 success: (res) => {
						 console.log("request success");
						 console.log(res.data);
						 if(res.data['state'] == 1){
							 uni.showModal({
							 			title: '提示',
							 			content: res.data['msg'],
							 			showCancel: false,
							 			confirmText: '确定'
							 		});
							uni.navigateBack();
						 }else{
							 uni.showModal({
							 			title: '提示',
							 			content: res.data['msg'],
							 			showCancel: false,
							 			confirmText: '确定'
							 		});
						 }
					 },
					 fail:(res) =>{
						 console.log("修改密码失败");
						 }
					 })
				}else{
					uni.showModal({
								title: '提示',
								content: "两次输入的密码不一致",
								showCancel: false,
								confirmText: '确定'
							});
				}
			}
		}
	}
</script>

<style>
.loginbtn{
	color: white;
	background-color: #528FFF;
	border-radius: 10px;
}
</style>
